Add GenAI semconv attributes to native OTel spans#2854
Draft
etserend wants to merge 4 commits into
Draft
Conversation
Author
|
Here is example output |
aa95d2b to
6930f92
Compare
adityamehra
reviewed
Jun 12, 2026
|
|
||
| # Maps MCP JSON-RPC method names to GenAI semantic convention operation names. | ||
| # https://github.com/open-telemetry/semantic-conventions-genai/blob/main/docs/gen-ai/mcp.md | ||
| _METHOD_TO_GEN_AI_OPERATION: dict[str, str] = { |
There was a problem hiding this comment.
I don't think we should be mapping method name to operation name since it's redundant as we already have the mcp.method.name. We have have it for tool/call mcp methods but not sure about others.
But let me know if I missing the point.
There was a problem hiding this comment.
…, add gen_ai.prompt.name for prompts/get
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The existing otel_middleware and client-side spans only emitted mcp.method.name and jsonrpc.request.id. This enriches them with attributes defined in the OTel GenAI MCP semantic conventions:
gen_ai.operation.name— operation type derived from the method (execute_toolfor tools/call,list_toolsfor tools/list,read_resourcefor resources/read,get_promptfor prompts/get, etc.)gen_ai.tool.name— tool or prompt name from params.name when presentmcp.resource.uri— resource URI from params.uri or params.ref.urirpc.system = "mcp"— standard RPC system attributeMotivation and Context
The SDK already ships otel_middleware in
src/mcp/server/runner.pyproducing SpanKind.SERVER spans with W3C trace context propagation. Aligning the native span attributes with the GenAI semconv spec means every MCP-based framework and every distribution gets conformant telemetry without independently re-implementing span plumbing.How Has This Been Tested?
Adds three tests to tests/shared/test_otel.py:
Types of changes
Checklist
Additional context